/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.MStockMidlet;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author kien.tran
 */
public class SplashForm extends Canvas {

    private Display display;
    private MStockMidlet midlet;
    private String imagePath;
    private int formWidth, formHeight;

    public SplashForm(MStockMidlet midlet, Display display) {
        setFullScreenMode(true);

        this.display = display;
        this.midlet = midlet;

        this.formWidth = getWidth();
        this.formHeight = getHeight();

        if (formWidth >= 230) {
            this.imagePath = "/image/size240x320/";

        } else {
            this.imagePath = "/image/size176x208/";
        }

        midlet.setImagePath(imagePath);
    }

    public void paint(Graphics g) {
        setFullScreenMode(true);
        int x = 0, y = 0;

        this.formWidth = getWidth();
        this.formHeight = getHeight();

        //g.setColor(midlet.getStyle().getBodyStyle().getBgColor());
        g.setColor(0xd9557d);
        g.fillRect(x, y, formWidth, formHeight);

        Image screen = null;
        try {
            screen = Image.createImage(imagePath + "screen.png");
        } catch (IOException ex) {
            screen = null;
        }

        if (screen != null) {
            x = (formWidth - screen.getWidth()) / 2;
            y = (formHeight - screen.getHeight()) / 2;
            g.drawImage(screen, x, y, Graphics.TOP | Graphics.LEFT);
        }
    }

    public void show() {
        display.setCurrent(this);
    }
}
